<%--
  Created by IntelliJ IDEA.
  User: 97506
  Date: 2019/6/4
  Time: 20:56
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
    <%
        pageContext.setAttribute("APP_PATH", request.getContextPath());
    %>
    <title>员工列表</title>
    <script src="${APP_PATH}/static/js/jquery-3.4.1.min.js"></script>

    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css"
          integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"
            integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
            crossorigin="anonymous"></script>
</head>
<body>
<!--搭建显示页面-->
<div class="container">
    <!--标题-->
    <div class="row">
        <div class="col-lg-12">
            <h1>员工信息管理系统</h1>
        </div>
    </div>
    <!--按钮-->
    <div class="row">
        <div class="col-lg-4 col-lg-offset-10">
            <button type="button" class="btn btn-info">
                <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>新增
            </button>
            <button type="button" class="btn btn-danger">
                <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>删除
            </button>
        </div>
    </div>
    <!--显示表格数据-->
    <div class="row" style="margin-top: 20px">
        <div class="col-lg-12">
            <table class="table table-hover table-bordered">
                <tr>
                    <th>#</th>
                    <th>empName</th>
                    <th>gender</th>
                    <th>email</th>
                    <th>deptName</th>
                    <th></th>
                </tr>

                <c:forEach items="${emps.list}" var="emp">
                    <tr>
                        <th>${emp.empId}</th>
                        <th>${emp.epmName}</th>
                        <th>${emp.gender=='男'?'男':'女'}</th>
                        <th>${emp.email}</th>
                        <th>${emp.department.deptName}</th>
                        <th>
                            <button type="button" class="btn btn-warning btn-sm" aria-label="Left Align">
                                <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>修改
                            </button>
                            <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
                            <button type="button" class="btn btn-danger btn-sm" aria-label="Left Align">
                                <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>删除
                            </button>
                        </th>
                    </tr>
                </c:forEach>
            </table>
        </div>
    </div>
    <!--分页-->
    <div class="row">
        <!--分页信息-->
        <div class="col-lg-6">
            当前为<kbd>${emps.pageNum}</kbd>页，总共<kbd>${emps.pages}</kbd>页，总记录为<kbd>${emps.total}</kbd>项。
        </div>

        <!--分页条-->
        <div class="col-md-6">

            <nav aria-label="Page navigation">

                <ul class="pagination">

                    <li onclick="select_by_pagenum(1)"><a href="#">首页</a></li>

                    <c:if test="${emps.hasPreviousPage}">
                        <li onclick="select_by_pagenum('+result.extend.emps.pageNum-1+')">
                            <a href="#" aria-label="Previous">
                                <span aria-hidden="true">&laquo;</span>
                            </a>
                        </li>
                    </c:if>


                    <c:forEach items="${emps.navigatepageNums}" var="index">
                        <c:if test="${index == emps.pageNum}">
                            <li class="active" onclick="select_by_pagenum('+item+')"><a href="#">+item+</a></li>
                        </c:if>
                        <c:if test="${index != emps.pageNum}">
                            <li onclick="select_by_pagenum('+item+')"><a href="#">+item+</a></li>
                        </c:if>
                    </c:forEach>

                    <c:if test="${emps.hasNextPage}">
                        <li onclick="select_by_pagenum('+result.extend.emps.pageNum+1+')">
                            <a href="#" aria-label="Next">
                                <span aria-hidden="true">&raquo;</span>
                            </a>
                        </li>
                    </c:if>

                    <li><a href="${APP_PATH}/emps?pn=${emps.pages}">尾页</a></li>
                </ul>
            </nav>
        </div>
    </div>
</div>
<script>
    function select_by_pagenum(pn) {
        $.ajax({
            url: "${APP_PATH}/emps",
            type: "GET",
            data: {pn: pn},
            success: function (result) {
                build_table(result);
                build_page_nav(result);
                build_page_bar(result);
            }
        })
    }
</script>
</body>
</html>
